﻿
namespace Warl
{
    static class Settings
    {
        private static string startupPath;
        private static string appIniPath;
        private static string profileIniPath;

        public static void setPath(string path)
        {
            startupPath = path + "\\";
            //
            // cleanup of old Ini... will keep here for a couple versions
            if (System.IO.File.Exists(appIniPath)) { System.IO.File.Delete(startupPath + "Settings.ini"); }
            // end of clean up
            //
            appIniPath = startupPath + "AppSettings.ini";
            if (!System.IO.File.Exists(appIniPath)) { System.IO.File.Create(appIniPath); }
            //
            if (!System.IO.Directory.Exists(startupPath + "Profiles")) { System.IO.Directory.CreateDirectory(startupPath + "Profiles"); }
        }

        public static void setProfile(string profileName)
        {
            profileIniPath = startupPath + "\\Profiles\\" + profileName + ".ini";
            if (!System.IO.File.Exists(profileIniPath)) { System.IO.File.Create(profileIniPath); }
            //
            _wowPath       = null;
            _realmlistPath = null;
        }

        #region App Settings

        private static int _debugLvl = 0;
        public static int debugLvl
        {
            get
            {
                if (_debugLvl != 0) { return _debugLvl; }
                else { return new IniFile(appIniPath).GetInt16("Settings", "DebugLvl", 2); }
            }
            set { new IniFile(appIniPath).WriteValue("Settings", "DebugLvl", value); _debugLvl = value; }
        }

        #endregion

        #region Profile Settings

        private static string _wowPath;
        public static string wowPath
        {
            get
            {
                if (_wowPath != null) { return _wowPath; }
                else { return new IniFile(profileIniPath).GetString("Settings", "wowPath", null); }
            }
            set { new IniFile(profileIniPath).WriteValue("Settings", "wowPath", value); _wowPath = value; }
        }

        private static string _realmlistPath;
        public static string realmlistPath
        {
            get
            {
                if (_realmlistPath != null) { return _realmlistPath; }
                else { return new IniFile(profileIniPath).GetString("Settings", "realmlistPath", null); }
            }
            set { new IniFile(profileIniPath).WriteValue("Settings", "realmlistPath", value); _realmlistPath = value; }
        }

        #endregion
    }
}
